#ifndef _CPP_INI_H
#define _CPP_INI_H


#include <string>
#include <vector>
#include <map>
#include <assert.h>
#include <algorithm>
#include <fstream>
using namespace std;

typedef std::basic_string<TCHAR> tstring;

#ifdef  _UNICODE
#define tfstream std::wfstream
#else
#define tfstream std::fstream
#endif

class cppini
{
public:
	cppini();
	~cppini();

public:
	bool read(const tstring& path);
	bool save(const tstring& path);

public:
	int  add_section(tstring sec_name);
	int  del_section(tstring sec_name);

	void set_cur_section(tstring sec_name);
	
	int     get_int(tstring k, int def);
	tstring get_string(tstring k, tstring def);
	bool    get_bool(tstring k, bool def);
	
	void    set_int(tstring k, int v);
	void    set_str(tstring k, tstring v);
	void    set_bool(tstring k, bool b);

private:
	tstring parse_section(tfstream& in, tstring section);

	void write_1_section(tfstream& out, tstring section);

	void clean_line(tstring& line);

private:
	typedef map<tstring, tstring> MAPSTR;
	
	map<tstring, MAPSTR> m_map;
	tstring m_cur_section;
};

#endif